<!DOCTYPE html>
<html lang="" xml:lang="">
<head>

  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>4 Bash 字符串处理 | Linux学习</title>
  <meta name="description" content="4 Bash 字符串处理 | Linux学习" />
  <meta name="generator" content="bookdown 0.45 and GitBook 2.6.7" />

  <meta property="og:title" content="4 Bash 字符串处理 | Linux学习" />
  <meta property="og:type" content="book" />
  
  
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="4 Bash 字符串处理 | Linux学习" />
  
  
  

<meta name="author" content="易生信" />
<meta name="author" content="www.bic.ac.cn/Training" />


<meta name="date" content="2025-10-31" />

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  
  
<link rel="prev" href="LinuxGreatTools.html"/>
<link rel="next" href="bioinfo-tools.html"/>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />








<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>


<style type="text/css">
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<style type="text/css">
  
  div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
</style>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="http://https://mp.weixin.qq.com/s/i71OMaUu6QtcY0pt1njHQA">Hello</a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>前沿</a></li>
<li class="chapter" data-level="1" data-path="linux_basic.html"><a href="linux_basic.html"><i class="fa fa-check"></i><b>1</b> Linux初探，打开新世界的大门</a>
<ul>
<li class="chapter" data-level="1.1" data-path="linux_basic.html"><a href="linux_basic.html#basicDir"><i class="fa fa-check"></i><b>1.1</b> Linux系统简介和目录理解</a>
<ul>
<li class="chapter" data-level="1.1.1" data-path="linux_basic.html"><a href="linux_basic.html#why_linux"><i class="fa fa-check"></i><b>1.1.1</b> 为什么要用Linux系统</a></li>
<li class="chapter" data-level="1.1.2" data-path="linux_basic.html"><a href="linux_basic.html#linux_everywhere"><i class="fa fa-check"></i><b>1.1.2</b> Linux系统无处不在</a></li>
<li class="chapter" data-level="1.1.3" data-path="linux_basic.html"><a href="linux_basic.html#free_linux"><i class="fa fa-check"></i><b>1.1.3</b> 免费的Linux系统来一套</a></li>
<li class="chapter" data-level="1.1.4" data-path="linux_basic.html"><a href="linux_basic.html#linux_login"><i class="fa fa-check"></i><b>1.1.4</b> Linux系统登录-联系远方的她</a></li>
<li class="chapter" data-level="1.1.5" data-path="linux_basic.html"><a href="linux_basic.html#linux_cmd"><i class="fa fa-check"></i><b>1.1.5</b> 初识Linux系统 - 黑夜中的闪烁是你的落脚点</a></li>
<li class="chapter" data-level="1.1.6" data-path="linux_basic.html"><a href="linux_basic.html#my_computer"><i class="fa fa-check"></i><b>1.1.6</b> 我的电脑在哪？</a></li>
<li class="chapter" data-level="1.1.7" data-path="linux_basic.html"><a href="linux_basic.html#linux_system_hardware"><i class="fa fa-check"></i><b>1.1.7</b> 系统配置怎样？来看看256M硬盘的服务器</a></li>
<li class="chapter" data-level="1.1.8" data-path="linux_basic.html"><a href="linux_basic.html#directpry_show"><i class="fa fa-check"></i><b>1.1.8</b> 看下目录下都有什么</a></li>
<li class="chapter" data-level="1.1.9" data-path="linux_basic.html"><a href="linux_basic.html#mkdir"><i class="fa fa-check"></i><b>1.1.9</b> 新建一个目录</a></li>
<li class="chapter" data-level="1.1.10" data-path="linux_basic.html"><a href="linux_basic.html#cat_file"><i class="fa fa-check"></i><b>1.1.10</b> 访问文件</a></li>
<li class="chapter" data-level="1.1.11" data-path="linux_basic.html"><a href="linux_basic.html#com_parameter_help"><i class="fa fa-check"></i><b>1.1.11</b> 查看帮助，获取可用命令行参数</a></li>
<li class="chapter" data-level="1.1.12" data-path="linux_basic.html"><a href="linux_basic.html#first_summary"><i class="fa fa-check"></i><b>1.1.12</b> 小结</a></li>
<li class="chapter" data-level="1.1.13" data-path="linux_basic.html"><a href="linux_basic.html#first_exercise"><i class="fa fa-check"></i><b>1.1.13</b> 做个小测试</a></li>
</ul></li>
<li class="chapter" data-level="1.2" data-path="linux_basic.html"><a href="linux_basic.html#fileoperation"><i class="fa fa-check"></i><b>1.2</b> Linux下文件操作</a>
<ul>
<li class="chapter" data-level="1.2.1" data-path="linux_basic.html"><a href="linux_basic.html#tac_rev"><i class="fa fa-check"></i><b>1.2.1</b> 文件按行翻转和按列翻转</a></li>
<li class="chapter" data-level="1.2.2" data-path="linux_basic.html"><a href="linux_basic.html#new_file"><i class="fa fa-check"></i><b>1.2.2</b> 新建文件的n种方式</a></li>
<li class="chapter" data-level="1.2.3" data-path="linux_basic.html"><a href="linux_basic.html#file_cp_mv_rename_link"><i class="fa fa-check"></i><b>1.2.3</b> 文件拷贝、移动、重命名、软链</a></li>
<li class="chapter" data-level="1.2.4" data-path="linux_basic.html"><a href="linux_basic.html#linux_abnormal"><i class="fa fa-check"></i><b>1.2.4</b> Linux下命令的一些突发事故</a></li>
<li class="chapter" data-level="1.2.5" data-path="linux_basic.html"><a href="linux_basic.html#file_op_gzip_wc"><i class="fa fa-check"></i><b>1.2.5</b> 了解和操作你的文件</a></li>
<li class="chapter" data-level="1.2.6" data-path="linux_basic.html"><a href="linux_basic.html#second_exercise"><i class="fa fa-check"></i><b>1.2.6</b> 小结和练习</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path="linux_basic.html"><a href="linux_basic.html#shortcut"><i class="fa fa-check"></i><b>1.3</b> Linux终端常用快捷操作</a></li>
<li class="chapter" data-level="1.4" data-path="linux_basic.html"><a href="linux_basic.html#linuxSpecialSymbols"><i class="fa fa-check"></i><b>1.4</b> Linux 命令中的特殊符号</a></li>
<li class="chapter" data-level="1.5" data-path="linux_basic.html"><a href="linux_basic.html#stdinoutpipe"><i class="fa fa-check"></i><b>1.5</b> Linux下的标准输入、输出、重定向、管道</a></li>
<li class="chapter" data-level="1.6" data-path="linux_basic.html"><a href="linux_basic.html#filecontent"><i class="fa fa-check"></i><b>1.6</b> Linux文件内容操作</a>
<ul>
<li class="chapter" data-level="1.6.1" data-path="linux_basic.html"><a href="linux_basic.html#generate_file_seq"><i class="fa fa-check"></i><b>1.6.1</b> 命令组合生成文件</a></li>
<li class="chapter" data-level="1.6.2" data-path="linux_basic.html"><a href="linux_basic.html#sort_par"><i class="fa fa-check"></i><b>1.6.2</b> 文件排序原来有暗仓</a></li>
<li class="chapter" data-level="1.6.3" data-path="linux_basic.html"><a href="linux_basic.html#%E5%AE%9E%E6%88%98fasta%E5%BA%8F%E5%88%97%E6%8F%90%E5%8F%96-fasta_extract"><i class="fa fa-check"></i><b>1.6.3</b> 实战FASTA序列提取 [#fasta_extract}</a></li>
</ul></li>
<li class="chapter" data-level="1.7" data-path="linux_basic.html"><a href="linux_basic.html#linux_search"><i class="fa fa-check"></i><b>1.7</b> Linux下的查找命令 - 文件哪里跑</a>
<ul>
<li class="chapter" data-level="1.7.1" data-path="linux_basic.html"><a href="linux_basic.html#seach_cmmand"><i class="fa fa-check"></i><b>1.7.1</b> 命令/可执行程序查找 - 定位脚本的位置</a></li>
<li class="chapter" data-level="1.7.2" data-path="linux_basic.html"><a href="linux_basic.html#locate"><i class="fa fa-check"></i><b>1.7.2</b> locate普通文件快速定位</a></li>
<li class="chapter" data-level="1.7.3" data-path="linux_basic.html"><a href="linux_basic.html#find"><i class="fa fa-check"></i><b>1.7.3</b> find让文件无处可逃 find</a></li>
<li class="chapter" data-level="1.7.4" data-path="linux_basic.html"><a href="linux_basic.html#grep_file"><i class="fa fa-check"></i><b>1.7.4</b> 按文件内容查找 grep</a></li>
</ul></li>
<li class="chapter" data-level="1.8" data-path="linux_basic.html"><a href="linux_basic.html#grep_faster"><i class="fa fa-check"></i><b>1.8</b> 一句话加速grep近30倍</a>
<ul>
<li class="chapter" data-level="1.8.1" data-path="linux_basic.html"><a href="linux_basic.html#grep_single_gene"><i class="fa fa-check"></i><b>1.8.1</b> 获取单基因表达量</a></li>
<li class="chapter" data-level="1.8.2" data-path="linux_basic.html"><a href="linux_basic.html#grep_multiple_gene"><i class="fa fa-check"></i><b>1.8.2</b> 那如果获取多个基因怎么操作呢？</a></li>
</ul></li>
<li class="chapter" data-level="1.9" data-path="linux_basic.html"><a href="linux_basic.html#linux%E4%B8%8B%E7%9A%84%E6%89%B9%E9%87%8F%E6%93%8D%E4%BD%9C"><i class="fa fa-check"></i><b>1.9</b> Linux下的批量操作</a></li>
<li class="chapter" data-level="1.10" data-path="linux_basic.html"><a href="linux_basic.html#top"><i class="fa fa-check"></i><b>1.10</b> 监控程序的运行时间和资源占用</a></li>
<li class="chapter" data-level="1.11" data-path="linux_basic.html"><a href="linux_basic.html#%E4%B8%8D%E5%90%8C%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%8D%A2%E8%A1%8C%E7%AC%A6%E4%B8%8D%E5%85%BC%E5%AE%B9%E5%BC%95%E5%8F%91%E7%9A%84%E9%97%AE%E9%A2%98"><i class="fa fa-check"></i><b>1.11</b> 不同系统的换行符不兼容引发的问题</a>
<ul>
<li class="chapter" data-level="1.11.1" data-path="linux_basic.html"><a href="linux_basic.html#winddows-%E7%9A%84%E7%A8%8B%E5%BA%8F%E4%BC%A0%E5%88%B0-linux%E4%B8%8D%E8%83%BD%E8%BF%90%E8%A1%8C"><i class="fa fa-check"></i><b>1.11.1</b> Winddows 的程序传到 Linux不能运行</a></li>
<li class="chapter" data-level="1.11.2" data-path="linux_basic.html"><a href="linux_basic.html#winddows-%E7%9A%84%E6%95%B0%E6%8D%AE%E4%BC%A0%E5%88%B0-linux%E4%B8%8D%E8%83%BD%E5%8C%B9%E9%85%8D"><i class="fa fa-check"></i><b>1.11.2</b> Winddows 的数据传到 Linux不能匹配</a></li>
<li class="chapter" data-level="1.11.3" data-path="linux_basic.html"><a href="linux_basic.html#linux-%E7%9A%84%E6%95%B0%E6%8D%AE%E4%BC%A0%E5%88%B0-windows-%E6%89%93%E5%BC%80%E4%B8%8D%E6%8D%A2%E8%A1%8C"><i class="fa fa-check"></i><b>1.11.3</b> Linux 的数据传到 Windows 打开不换行</a></li>
</ul></li>
<li class="chapter" data-level="1.12" data-path="linux_basic.html"><a href="linux_basic.html#references"><i class="fa fa-check"></i><b>1.12</b> References</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="softinstall.html"><a href="softinstall.html"><i class="fa fa-check"></i><b>2</b> Linux下软件安装相关</a>
<ul>
<li class="chapter" data-level="2.1" data-path="softinstall.html"><a href="softinstall.html#fileattributeplusX"><i class="fa fa-check"></i><b>2.1</b> 文件属性和可执行属性</a>
<ul>
<li class="chapter" data-level="2.1.1" data-path="softinstall.html"><a href="softinstall.html#fileattribute"><i class="fa fa-check"></i><b>2.1.1</b> 文件属性</a></li>
<li class="chapter" data-level="2.1.2" data-path="softinstall.html"><a href="softinstall.html#executable"><i class="fa fa-check"></i><b>2.1.2</b> 可执行属性</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="softinstall.html"><a href="softinstall.html#PATH_path_which"><i class="fa fa-check"></i><b>2.2</b> PATH和path，傻傻分不清</a>
<ul>
<li class="chapter" data-level="2.2.1" data-path="softinstall.html"><a href="softinstall.html#last_but_not_least"><i class="fa fa-check"></i><b>2.2.1</b> 小事也不能忽略</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="softinstall.html"><a href="softinstall.html#softInstallways"><i class="fa fa-check"></i><b>2.3</b> 软件安装的几种传统方式</a>
<ul>
<li class="chapter" data-level="2.3.1" data-path="softinstall.html"><a href="softinstall.html#system_package"><i class="fa fa-check"></i><b>2.3.1</b> 系统包管理器安装</a></li>
<li class="chapter" data-level="2.3.2" data-path="softinstall.html"><a href="softinstall.html#binary"><i class="fa fa-check"></i><b>2.3.2</b> 下载二进制文件</a></li>
<li class="chapter" data-level="2.3.3" data-path="softinstall.html"><a href="softinstall.html#configure_make_install"><i class="fa fa-check"></i><b>2.3.3</b> 源码编译安装</a></li>
<li class="chapter" data-level="2.3.4" data-path="softinstall.html"><a href="softinstall.html#pythonpac"><i class="fa fa-check"></i><b>2.3.4</b> Python包的安装</a></li>
<li class="chapter" data-level="2.3.5" data-path="softinstall.html"><a href="softinstall.html#anaconda_fear"><i class="fa fa-check"></i><b>2.3.5</b> Anaconda的两个福利</a></li>
<li class="chapter" data-level="2.3.6" data-path="softinstall.html"><a href="softinstall.html#R_install"><i class="fa fa-check"></i><b>2.3.6</b> R和R包的安装</a></li>
<li class="chapter" data-level="2.3.7" data-path="softinstall.html"><a href="softinstall.html#perl_package"><i class="fa fa-check"></i><b>2.3.7</b> Perl包的安装</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="softinstall.html"><a href="softinstall.html#condaInstall"><i class="fa fa-check"></i><b>2.4</b> Conda安装配置生物信息软件</a>
<ul>
<li class="chapter" data-level="2.4.1" data-path="softinstall.html"><a href="softinstall.html#condaInstallConfig"><i class="fa fa-check"></i><b>2.4.1</b> Conda安装和配置</a></li>
<li class="chapter" data-level="2.4.2" data-path="softinstall.html"><a href="softinstall.html#conda_basic"><i class="fa fa-check"></i><b>2.4.2</b> Conda基本使用</a></li>
<li class="chapter" data-level="2.4.3" data-path="softinstall.html"><a href="softinstall.html#conda_channel"><i class="fa fa-check"></i><b>2.4.3</b> Conda的channel</a></li>
<li class="chapter" data-level="2.4.4" data-path="softinstall.html"><a href="softinstall.html#conda_environment"><i class="fa fa-check"></i><b>2.4.4</b> 创建不同的软件运行环境</a></li>
<li class="chapter" data-level="2.4.5" data-path="softinstall.html"><a href="softinstall.html#remove_conda"><i class="fa fa-check"></i><b>2.4.5</b> 移除某个conda环境</a></li>
<li class="chapter" data-level="2.4.6" data-path="softinstall.html"><a href="softinstall.html#conda-R"><i class="fa fa-check"></i><b>2.4.6</b> Conda配置R</a></li>
<li class="chapter" data-level="2.4.7" data-path="softinstall.html"><a href="softinstall.html#conda_simple"><i class="fa fa-check"></i><b>2.4.7</b> Conda环境简化运行</a></li>
<li class="chapter" data-level="2.4.8" data-path="softinstall.html"><a href="softinstall.html#conda_bak"><i class="fa fa-check"></i><b>2.4.8</b> Conda环境备份</a></li>
<li class="chapter" data-level="2.4.9" data-path="softinstall.html"><a href="softinstall.html#conda_import"><i class="fa fa-check"></i><b>2.4.9</b> Conda环境导出和导入</a></li>
<li class="chapter" data-level="2.4.10" data-path="softinstall.html"><a href="softinstall.html#cond_segment_fault"><i class="fa fa-check"></i><b>2.4.10</b> Conda软件安装 core dump error/Segment fault/段错误 怎么办</a></li>
<li class="chapter" data-level="2.4.11" data-path="softinstall.html"><a href="softinstall.html#conda_slow"><i class="fa fa-check"></i><b>2.4.11</b> Conda为什么越来越慢？</a></li>
<li class="chapter" data-level="2.4.12" data-path="softinstall.html"><a href="softinstall.html#conda_how_work"><i class="fa fa-check"></i><b>2.4.12</b> Conda是如何工作的</a></li>
<li class="chapter" data-level="2.4.13" data-path="softinstall.html"><a href="softinstall.html#cond_which_step_slow"><i class="fa fa-check"></i><b>2.4.13</b> Conda哪一步慢？</a></li>
<li class="chapter" data-level="2.4.14" data-path="softinstall.html"><a href="softinstall.html#cond_accelarate"><i class="fa fa-check"></i><b>2.4.14</b> 如何提速Conda</a></li>
<li class="chapter" data-level="2.4.15" data-path="softinstall.html"><a href="softinstall.html#conda_downlaod_fast"><i class="fa fa-check"></i><b>2.4.15</b> 下载提速</a></li>
<li class="chapter" data-level="2.4.16" data-path="softinstall.html"><a href="softinstall.html#conda_pack"><i class="fa fa-check"></i><b>2.4.16</b> 使用conda-pack直接从已经安装好的地方拷贝一份 (同一操作系统)</a></li>
</ul></li>
<li class="chapter" data-level="2.5" data-path="softinstall.html"><a href="softinstall.html#docker"><i class="fa fa-check"></i><b>2.5</b> Docker安装</a>
<ul>
<li class="chapter" data-level="2.5.1" data-path="softinstall.html"><a href="softinstall.html#docker_what"><i class="fa fa-check"></i><b>2.5.1</b> Docker能做什么</a></li>
<li class="chapter" data-level="2.5.2" data-path="softinstall.html"><a href="softinstall.html#docker_basic"><i class="fa fa-check"></i><b>2.5.2</b> Docker的几个基本概念</a></li>
<li class="chapter" data-level="2.5.3" data-path="softinstall.html"><a href="softinstall.html#docker_install"><i class="fa fa-check"></i><b>2.5.3</b> 安装和配置</a></li>
<li class="chapter" data-level="2.5.4" data-path="softinstall.html"><a href="softinstall.html#docker_priviledges"><i class="fa fa-check"></i><b>2.5.4</b> Docker用户权限</a></li>
<li class="chapter" data-level="2.5.5" data-path="softinstall.html"><a href="softinstall.html#docker_try"><i class="fa fa-check"></i><b>2.5.5</b> Docker试用</a></li>
<li class="chapter" data-level="2.5.6" data-path="softinstall.html"><a href="softinstall.html#docker_basic_operation"><i class="fa fa-check"></i><b>2.5.6</b> Docker系统基本操作</a></li>
<li class="chapter" data-level="2.5.7" data-path="softinstall.html"><a href="softinstall.html#Dockerfile"><i class="fa fa-check"></i><b>2.5.7</b> 使用Dockerfile自动构建镜像</a></li>
<li class="chapter" data-level="2.5.8" data-path="softinstall.html"><a href="softinstall.html#docker_single_process"><i class="fa fa-check"></i><b>2.5.8</b> Docker的特征</a></li>
<li class="chapter" data-level="2.5.9" data-path="softinstall.html"><a href="softinstall.html#docker_attention"><i class="fa fa-check"></i><b>2.5.9</b> Docker使用注意</a></li>
</ul></li>
<li class="chapter" data-level="2.6" data-path="softinstall.html"><a href="softinstall.html#makefile"><i class="fa fa-check"></i><b>2.6</b> Makefile知识</a>
<ul>
<li class="chapter" data-level="2.6.1" data-path="softinstall.html"><a href="softinstall.html#docker_ref"><i class="fa fa-check"></i><b>2.6.1</b> 参考</a></li>
</ul></li>
<li class="chapter" data-level="2.7" data-path="softinstall.html"><a href="softinstall.html#references-1"><i class="fa fa-check"></i><b>2.7</b> References</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html"><i class="fa fa-check"></i><b>3</b> Linux神器</a>
<ul>
<li class="chapter" data-level="3.1" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#regularExpr"><i class="fa fa-check"></i><b>3.1</b> 正则表达式替换文本随心所欲</a></li>
<li class="chapter" data-level="3.2" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#awk"><i class="fa fa-check"></i><b>3.2</b> awk-生信分析不可缺少</a>
<ul>
<li class="chapter" data-level="3.2.1" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#awk_explain"><i class="fa fa-check"></i><b>3.2.1</b> awk基本参数解释</a></li>
<li class="chapter" data-level="3.2.2" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#awk_common_op"><i class="fa fa-check"></i><b>3.2.2</b> awk基本常见操作</a></li>
<li class="chapter" data-level="3.2.3" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#awk_combine"><i class="fa fa-check"></i><b>3.2.3</b> awk糅合操作 - 命令组合体现魅力</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#sed"><i class="fa fa-check"></i><b>3.3</b> SED命令 - 文本替换舍我其谁</a>
<ul>
<li class="chapter" data-level="3.3.1" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#sed_basic"><i class="fa fa-check"></i><b>3.3.1</b> sed基本参数解释</a></li>
<li class="chapter" data-level="3.3.2" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#sed_common"><i class="fa fa-check"></i><b>3.3.2</b> 常见操作</a></li>
</ul></li>
<li class="chapter" data-level="3.4" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#vim"><i class="fa fa-check"></i><b>3.4</b> VIM的使用</a>
<ul>
<li class="chapter" data-level="3.4.1" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#vim_first"><i class="fa fa-check"></i><b>3.4.1</b> 初识VIM</a></li>
<li class="chapter" data-level="3.4.2" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#vim_re"><i class="fa fa-check"></i><b>3.4.2</b> VIM中使用正则表达式</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#rename_all"><i class="fa fa-check"></i><b>3.5</b> 有了这些，文件批量重命名还需要求助其它工具吗？</a>
<ul>
<li class="chapter" data-level="3.5.1" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#rename_simple"><i class="fa fa-check"></i><b>3.5.1</b> 简单重命名</a></li>
<li class="chapter" data-level="3.5.2" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#rename_complex"><i class="fa fa-check"></i><b>3.5.2</b> 复杂重命名</a></li>
</ul></li>
<li class="chapter" data-level="3.6" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#nohup"><i class="fa fa-check"></i><b>3.6</b> 耗时很长的程序忘加nohup就运行了怎么办？</a></li>
<li class="chapter" data-level="3.7" data-path="LinuxGreatTools.html"><a href="LinuxGreatTools.html#references-2"><i class="fa fa-check"></i><b>3.7</b> References</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="bash_string.html"><a href="bash_string.html"><i class="fa fa-check"></i><b>4</b> Bash 字符串处理</a>
<ul>
<li class="chapter" data-level="4.1" data-path="bash_string.html"><a href="bash_string.html#bash_specific"><i class="fa fa-check"></i><b>4.1</b> Bash特殊字符</a></li>
<li class="chapter" data-level="4.2" data-path="bash_string.html"><a href="bash_string.html#bash_variable"><i class="fa fa-check"></i><b>4.2</b> Bash变量</a></li>
<li class="chapter" data-level="4.3" data-path="bash_string.html"><a href="bash_string.html#bash_operator"><i class="fa fa-check"></i><b>4.3</b> Bash操作符</a></li>
<li class="chapter" data-level="4.4" data-path="bash_string.html"><a href="bash_string.html#bash_logic"><i class="fa fa-check"></i><b>4.4</b> Shell中条件和test命令</a></li>
<li class="chapter" data-level="4.5" data-path="bash_string.html"><a href="bash_string.html#bash_flow"><i class="fa fa-check"></i><b>4.5</b> Shell流控制</a></li>
<li class="chapter" data-level="4.6" data-path="bash_string.html"><a href="bash_string.html#bash_function"><i class="fa fa-check"></i><b>4.6</b> Shell函数</a></li>
<li class="chapter" data-level="4.7" data-path="bash_string.html"><a href="bash_string.html#bash_inputoutput"><i class="fa fa-check"></i><b>4.7</b> 输入输出</a></li>
<li class="chapter" data-level="4.8" data-path="bash_string.html"><a href="bash_string.html#command_parameter"><i class="fa fa-check"></i><b>4.8</b> 命令行处理 命令行处理命令</a></li>
<li class="chapter" data-level="4.9" data-path="bash_string.html"><a href="bash_string.html#process_monitor"><i class="fa fa-check"></i><b>4.9</b> 进程和作业控制</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html"><i class="fa fa-check"></i><b>5</b> Bioinfo tools</a>
<ul>
<li class="chapter" data-level="5.1" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#cas9"><i class="fa fa-check"></i><b>5.1</b> 寻找Cas9的同源基因并进行进化分析</a></li>
<li class="chapter" data-level="5.2" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif"><i class="fa fa-check"></i><b>5.2</b> 如何获取目标基因的转录因子（上）——biomart下载基因和motif位置信息</a>
<ul>
<li class="chapter" data-level="5.2.1" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_1"><i class="fa fa-check"></i><b>5.2.1</b> 1. 文件准备</a></li>
<li class="chapter" data-level="5.2.2" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_2"><i class="fa fa-check"></i><b>5.2.2</b> 2. 什么是bed文件？</a></li>
<li class="chapter" data-level="5.2.3" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_3"><i class="fa fa-check"></i><b>5.2.3</b> 3. BioMart数据下载</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_4"><i class="fa fa-check"></i><b>5.3</b> 如何获取目标基因的转录因子（下）——Linux命令获取目标基因TF</a>
<ul>
<li class="chapter" data-level="5.3.1" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_5"><i class="fa fa-check"></i><b>5.3.1</b> 1. 基础回顾</a></li>
<li class="chapter" data-level="5.3.2" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_6"><i class="fa fa-check"></i><b>5.3.2</b> 2. 文件格式处理</a></li>
<li class="chapter" data-level="5.3.3" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_7"><i class="fa fa-check"></i><b>5.3.3</b> 3. 计算基因的启动子区</a></li>
<li class="chapter" data-level="5.3.4" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_8"><i class="fa fa-check"></i><b>5.3.4</b> 4. 取两文件的交集</a></li>
<li class="chapter" data-level="5.3.5" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_9"><i class="fa fa-check"></i><b>5.3.5</b> 5. 提取我们关注的基因</a></li>
<li class="chapter" data-level="5.3.6" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#biomart_motif_10"><i class="fa fa-check"></i><b>5.3.6</b> 重点总结</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#emboss"><i class="fa fa-check"></i><b>5.4</b> emboss的使用</a></li>
<li class="chapter" data-level="5.5" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#samtools_snp"><i class="fa fa-check"></i><b>5.5</b> 使用samtools计算SNP</a></li>
<li class="chapter" data-level="5.6" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#bedtools"><i class="fa fa-check"></i><b>5.6</b> Bedtools使用</a></li>
<li class="chapter" data-level="5.7" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#sra_tools"><i class="fa fa-check"></i><b>5.7</b> SRA toolkit使用</a></li>
<li class="chapter" data-level="5.8" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#bioinfo_pipeline"><i class="fa fa-check"></i><b>5.8</b> 生信流程开发</a></li>
<li class="chapter" data-level="5.9" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#rsync"><i class="fa fa-check"></i><b>5.9</b> 数据同步和备份</a>
<ul>
<li class="chapter" data-level="5.9.1" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#scp"><i class="fa fa-check"></i><b>5.9.1</b> 原创拷贝scp</a></li>
<li class="chapter" data-level="5.9.2" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#rsync1"><i class="fa fa-check"></i><b>5.9.2</b> 镜像备份和增量同步 rsync</a></li>
<li class="chapter" data-level="5.9.3" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#rdiff_backup"><i class="fa fa-check"></i><b>5.9.3</b> 增量备份，记录各个版本 rdiff-backup</a></li>
</ul></li>
<li class="chapter" data-level="5.10" data-path="bioinfo-tools.html"><a href="bioinfo-tools.html#references-3"><i class="fa fa-check"></i><b>5.10</b> References</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html"><i class="fa fa-check"></i><b>6</b> 生物信息中Linux命令练习</a>
<ul>
<li class="chapter" data-level="6.1" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#gtf_chr"><i class="fa fa-check"></i><b>6.1</b> 统计GTF文件中染色体数目？</a></li>
<li class="chapter" data-level="6.2" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#gtf_num_gene"><i class="fa fa-check"></i><b>6.2</b> 统计GTF文件中基因数目？</a></li>
<li class="chapter" data-level="6.3" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#gtf_exon_length"><i class="fa fa-check"></i><b>6.3</b> 计算GTF中外显子总长度？</a></li>
<li class="chapter" data-level="6.4" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#gtf_transcript_num"><i class="fa fa-check"></i><b>6.4</b> 计算GTF文件中基因所拥有的平均转录本数目</a></li>
<li class="chapter" data-level="6.5" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#fasta"><i class="fa fa-check"></i><b>6.5</b> 生成一个多行Fasta测试序列供后续运算 (也可使用我们前面提供的脚本生成)</a></li>
<li class="chapter" data-level="6.6" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#fasta_uppercase"><i class="fa fa-check"></i><b>6.6</b> <code>test.fa</code>中的序列全转成大写</a></li>
<li class="chapter" data-level="6.7" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#fasta_len"><i class="fa fa-check"></i><b>6.7</b> 计算多行FASTA文件<code>test.fa</code>中每条序列长度</a></li>
<li class="chapter" data-level="6.8" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#fasta_format"><i class="fa fa-check"></i><b>6.8</b> 多行FASTA转单行FASTA序列</a></li>
<li class="chapter" data-level="6.9" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#fasta_name"><i class="fa fa-check"></i><b>6.9</b> 取出单行FASTA文件中序列长度大于40的序列的名字</a></li>
<li class="chapter" data-level="6.10" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#id_extract"><i class="fa fa-check"></i><b>6.10</b> 分别用<code>awk</code>和<code>grep</code>从<code>test.fa</code>中提取给定ID对应的序列</a></li>
<li class="chapter" data-level="6.11" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#standard"><i class="fa fa-check"></i><b>6.11</b> 利用AWK对基因表达数据进行标准化</a></li>
<li class="chapter" data-level="6.12" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#skip_first_row"><i class="fa fa-check"></i><b>6.12</b> 写出3种写法，去掉上一题<code>test.expr</code>矩阵中的第一行？</a></li>
<li class="chapter" data-level="6.13" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#add_row"><i class="fa fa-check"></i><b>6.13</b> 分别用<code>awk</code>和<code>sed</code>给<code>test.expr</code>矩阵加上标题行？</a></li>
<li class="chapter" data-level="6.14" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#bam"><i class="fa fa-check"></i><b>6.14</b> 给定一个<code>BAM</code>文件，怎么计算有多少基因组区域被测到了？平均测序深度是多少？</a></li>
<li class="chapter" data-level="6.15" data-path="bioinfo_linux.html"><a href="bioinfo_linux.html#jaccard"><i class="fa fa-check"></i><b>6.15</b> 如何使用<code>bedtools</code>的其它工具或其它Linux命令实现<code>bedtools jaccard</code>子功能？</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="supplemental.html"><a href="supplemental.html"><i class="fa fa-check"></i><b>7</b> Supplemental</a></li>
<li class="chapter" data-level="8" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html"><i class="fa fa-check"></i><b>8</b> 生信教程文章集锦</a>
<ul>
<li class="chapter" data-level="8.1" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%94%9F%E4%BF%A1%E5%AE%9D%E5%85%B8"><i class="fa fa-check"></i><b>8.1</b> 生信宝典</a>
<ul>
<li class="chapter" data-level="8.1.1" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%B3%BB%E5%88%97%E6%95%99%E7%A8%8B"><i class="fa fa-check"></i><b>8.1.1</b> 系列教程</a></li>
<li class="chapter" data-level="8.1.2" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#ngs%E5%88%86%E6%9E%90%E5%B7%A5%E5%85%B7%E8%AF%84%E4%BC%B0"><i class="fa fa-check"></i><b>8.1.2</b> NGS分析工具评估</a></li>
<li class="chapter" data-level="8.1.3" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%AE%8F%E5%9F%BA%E5%9B%A0%E7%BB%84%E6%95%99%E7%A8%8B"><i class="fa fa-check"></i><b>8.1.3</b> 宏基因组教程</a></li>
<li class="chapter" data-level="8.1.4" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%B3%BB%E5%88%97%E5%AE%A3%E4%BC%A0"><i class="fa fa-check"></i><b>8.1.4</b> 系列宣传</a></li>
<li class="chapter" data-level="8.1.5" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%94%9F%E4%BF%A1%E7%94%9F%E7%89%A9%E7%9F%A5%E8%AF%86"><i class="fa fa-check"></i><b>8.1.5</b> 生信生物知识</a></li>
<li class="chapter" data-level="8.1.6" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E6%96%87%E7%8C%AE%E7%B2%BE%E8%AF%BB"><i class="fa fa-check"></i><b>8.1.6</b> 文献精读</a></li>
<li class="chapter" data-level="8.1.7" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#linux"><i class="fa fa-check"></i><b>8.1.7</b> Linux</a></li>
<li class="chapter" data-level="8.1.8" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#circos%E7%B3%BB%E5%88%97"><i class="fa fa-check"></i><b>8.1.8</b> CIRCOS系列</a></li>
<li class="chapter" data-level="8.1.9" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#r%E7%BB%9F%E8%AE%A1%E5%92%8C%E4%BD%9C%E5%9B%BE"><i class="fa fa-check"></i><b>8.1.9</b> R统计和作图</a></li>
<li class="chapter" data-level="8.1.10" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E6%89%A9%E5%A2%9E%E5%AD%90%E4%B8%89%E6%AD%A5%E6%9B%B2"><i class="fa fa-check"></i><b>8.1.10</b> 扩增子三步曲</a></li>
<li class="chapter" data-level="8.1.11" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%AE%8F%E5%9F%BA%E5%9B%A0%E7%BB%84%E5%88%86%E6%9E%90%E4%B8%93%E9%A2%98"><i class="fa fa-check"></i><b>8.1.11</b> 宏基因组分析专题</a></li>
<li class="chapter" data-level="8.1.12" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#ngs%E5%9F%BA%E7%A1%80"><i class="fa fa-check"></i><b>8.1.12</b> NGS基础</a></li>
<li class="chapter" data-level="8.1.13" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%99%8C%E7%97%87%E6%95%B0%E6%8D%AE%E5%BA%93"><i class="fa fa-check"></i><b>8.1.13</b> 癌症数据库</a></li>
<li class="chapter" data-level="8.1.14" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#python"><i class="fa fa-check"></i><b>8.1.14</b> Python</a></li>
<li class="chapter" data-level="8.1.15" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#ngs%E8%BD%AF%E4%BB%B6"><i class="fa fa-check"></i><b>8.1.15</b> NGS软件</a></li>
<li class="chapter" data-level="8.1.16" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#cytoscape%E7%BD%91%E7%BB%9C%E5%9B%BE"><i class="fa fa-check"></i><b>8.1.16</b> Cytoscape网络图</a></li>
<li class="chapter" data-level="8.1.17" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%88%86%E5%AD%90%E5%AF%B9%E6%8E%A5"><i class="fa fa-check"></i><b>8.1.17</b> 分子对接</a></li>
<li class="chapter" data-level="8.1.18" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%94%9F%E4%BF%A1%E5%AE%9D%E5%85%B8%E4%B9%8B%E5%82%BB%E7%93%9C%E5%BC%8F"><i class="fa fa-check"></i><b>8.1.18</b> 生信宝典之傻瓜式</a></li>
<li class="chapter" data-level="8.1.19" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%94%9F%E4%BF%A1%E4%BA%BA%E5%86%99%E7%A8%8B%E5%BA%8F"><i class="fa fa-check"></i><b>8.1.19</b> 生信人写程序</a></li>
<li class="chapter" data-level="8.1.20" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%B0%8F%E6%8A%80%E5%B7%A7%E7%B3%BB%E5%88%97"><i class="fa fa-check"></i><b>8.1.20</b> 小技巧系列</a></li>
<li class="chapter" data-level="8.1.21" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E6%8B%9B%E8%81%98"><i class="fa fa-check"></i><b>8.1.21</b> 招聘</a></li>
</ul></li>
<li class="chapter" data-level="8.2" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%AE%8F%E5%9F%BA%E5%9B%A0%E7%BB%84"><i class="fa fa-check"></i><b>8.2</b> 宏基因组</a>
<ul>
<li class="chapter" data-level="8.2.1" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%B2%BE%E9%80%89%E6%96%87%E7%AB%A0%E6%8E%A8%E8%8D%90"><i class="fa fa-check"></i><b>8.2.1</b> 精选文章推荐</a></li>
<li class="chapter" data-level="8.2.2" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%9F%B9%E8%AE%AD%E4%BC%9A%E8%AE%AE%E5%BE%81%E7%A8%BF%E6%8B%9B%E8%81%98"><i class="fa fa-check"></i><b>8.2.2</b> 培训、会议、征稿、招聘</a></li>
<li class="chapter" data-level="8.2.3" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%A7%91%E7%A0%94%E7%BB%8F%E9%AA%8C"><i class="fa fa-check"></i><b>8.2.3</b> 科研经验</a></li>
<li class="chapter" data-level="8.2.4" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E8%BD%AF%E4%BB%B6%E5%92%8C%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BD%BF%E7%94%A8"><i class="fa fa-check"></i><b>8.2.4</b> 软件和数据库使用</a></li>
<li class="chapter" data-level="8.2.5" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E6%89%A9%E5%A2%9E%E5%AD%90%E5%AD%A6%E4%B9%A0%E4%B8%89%E6%AD%A5%E6%9B%B2"><i class="fa fa-check"></i><b>8.2.5</b> 扩增子学习三步曲</a></li>
<li class="chapter" data-level="8.2.6" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%AE%8F%E5%9F%BA%E5%9B%A0%E7%BB%84%E5%88%86%E6%9E%90%E4%B8%93%E9%A2%98-1"><i class="fa fa-check"></i><b>8.2.6</b> 宏基因组分析专题</a></li>
<li class="chapter" data-level="8.2.7" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#r%E7%BB%9F%E8%AE%A1%E7%BB%98%E5%9B%BE"><i class="fa fa-check"></i><b>8.2.7</b> R统计绘图</a></li>
<li class="chapter" data-level="8.2.8" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%AE%9E%E9%AA%8C%E8%AE%BE%E8%AE%A1%E4%B8%8E%E6%8A%80%E6%9C%AF"><i class="fa fa-check"></i><b>8.2.8</b> 实验设计与技术</a></li>
<li class="chapter" data-level="8.2.9" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86"><i class="fa fa-check"></i><b>8.2.9</b> 基础知识</a></li>
<li class="chapter" data-level="8.2.10" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%BF%85%E8%AF%BB%E7%BB%BC%E8%BF%B0"><i class="fa fa-check"></i><b>8.2.10</b> 必读综述</a></li>
<li class="chapter" data-level="8.2.11" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E9%AB%98%E5%88%86%E6%96%87%E7%AB%A0%E5%A5%97%E8%B7%AF%E8%A7%A3%E8%AF%BB"><i class="fa fa-check"></i><b>8.2.11</b> 高分文章套路解读</a></li>
<li class="chapter" data-level="8.2.12" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E7%A7%91%E6%99%AE%E8%A7%86%E9%A2%91-%E5%AF%93%E6%95%99%E4%BA%8E%E4%B9%90"><i class="fa fa-check"></i><b>8.2.12</b> 科普视频-寓教于乐</a></li>
<li class="chapter" data-level="8.2.13" data-path="生信教程文章集锦.html"><a href="生信教程文章集锦.html#%E5%8F%8B%E5%86%9B%E6%96%87%E7%AB%A0%E6%B1%87%E6%80%BB%E6%8E%A8%E8%8D%90"><i class="fa fa-check"></i><b>8.2.13</b> 友军文章汇总推荐</a></li>
</ul></li>
</ul></li>
<li class="divider"></li>
<li><a href="mailto:chentong_biology@163.com" target="blank">chentong_biology@163.com</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Linux学习</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="bash_string" class="section level1 hasAnchor" number="4">
<h1><span class="header-section-number">4</span> Bash 字符串处理<a href="bash_string.html#bash_string" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<div id="bash_specific" class="section level2 hasAnchor" number="4.1">
<h2><span class="header-section-number">4.1</span> Bash特殊字符<a href="bash_string.html#bash_specific" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ol style="list-style-type: decimal">
<li>通配符:</li>
</ol>
<p><code>*</code>: 匹配任何字符</p>
<p><code>**</code>: 匹配任何字符串</p>
<p><code>*?</code>: 匹配任何单个字符</p>
<ol start="2" style="list-style-type: decimal">
<li>集合运算符</li>
</ol>
<p>用一些单个字、一个连续范围或断续的字符集合作为通配符</p>
<p><code>[a-z]</code>: 用字符集合作通配符匹配单个字符, 如: <code>[aeiou]</code>, <code>[a-o]</code>, <code>[A-Z]</code>, <code>[0-9]</code></p>
<p><code>[!A-Za-z0-9]</code>: 除了集合外的所有字符组成的集合作通配符</p>
<ol start="3" style="list-style-type: decimal">
<li>花括号展开式（可以嵌套）:</li>
</ol>
<p><code>c{a{r,t,n}, b{r,t,n}}s</code> 可以匹配<code>cars</code> <code>cats</code> <code>cans</code> <code>cbrs</code> <code>cbts</code> <code>cbns</code></p>
<ol start="4" style="list-style-type: decimal">
<li>其它特殊字符:</li>
</ol>
<p><code>()</code>: 子shell运行；比如 <code>(cd current_dir; mdkir ysx)</code>进入<code>current_dir</code>目录，新建<code>ysx</code>文件夹，运行完之后还在当前目录。</p>
<p><code>'</code>: 强引用字符串, 不解释特殊字符</p>
<p><code>"</code>: 弱引用字符串, 解释所有特殊字符</p>
<p><code>;</code>: 命令分隔符（命令终止符）, 运行在一行里执行多条命令;一般在终端直接写判断语句或执行<code>for</code>循环时用。</p>
<p><code>#</code>: 行注释<br />
<code>$</code>: 变量表达式，变量解析
<code>&amp;</code>: 在后台执行命令，在<code>for</code>循环中也可用作命令分割符，取代<code>done</code>前面的<code>;</code></p>
</div>
<div id="bash_variable" class="section level2 hasAnchor" number="4.2">
<h2><span class="header-section-number">4.2</span> Bash变量<a href="bash_string.html#bash_variable" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ol style="list-style-type: decimal">
<li>自定义变量</li>
</ol>
<p>用户自定义的变量由字母、数字和下划线组成, 并且变量名的第一个字符不能为数字, 且变量名大小写敏感。</p>
<p><code>varname=value</code> <strong>注意bash不能在等号两侧留空格</strong></p>
<p>shell语言是非类型的解释型语言, 给一个变量赋值实际上就是定义了变量, 而且可以赋不同类型的值。引用变量有两种方式, <code>$varname</code>和<code>${varname}</code>, 为防止变量在字符串中产生歧义建议使用第二种方式, 引用未定义的变量其值为空。</p>
<pre><code>ct@ysx:~$ a=&quot;current_dir&quot;
ct@ysx:~$ echo ${a}
current_dir
ct@ysx:~$ echo $a
current_dir

#出错了
ct@ysx:~$ echo $agood

#引用变量时大括号的作用
ct@ysx:~$ echo ${a}good
current_dirgood
ct@ysx:~$ echo $a.good
current_dir.good

#出错了
ct@ysx:~$ echo $a_good

#引用变量时大括号的作用
ct@ysx:~$ echo ${a}_good
current_dir_good</code></pre>
<p>为了使变量可以在其它进程中使用, 需要将变量导出: <code>export varname</code></p>
<ol start="2" style="list-style-type: decimal">
<li>环境变量</li>
</ol>
<p>可以用<code>set</code>命令给变量赋值或查看环境变量值, 使用<code>unset</code>命令清除变量值, 使用<code>export</code>导出变量将可以使其它进程访问到该环境变量。可以把设置保存到<code>.bashrc</code>或<code>.bash_profile</code>中, 成为永久的环境变量。</p>
<p>环境变量不限于我们之前讲过的<a href="http://mp.weixin.qq.com/s/TNU7X2mhfVVffaJ7NRBuNA">可执行程序的环境变量、动态库、Python模块的环境变量</a>，任何变量都可以的。</p>
<ol start="3" style="list-style-type: decimal">
<li>位置变量</li>
</ol>
<p>位置变量对应于命令行参数, 其中<code>$0</code>为脚本名称, <code>$1</code>为第一个参数, 依次类推, 参数超过9个必须使用<code>${}</code>引用变量。shell保留这些变量, 不允许用户以另外的方式定义它们, 传给脚本或函数的位置变量是局部和只读的, 而其余变量为全局的（可以用local关键字声明为局部）。</p>
<ol start="4" style="list-style-type: decimal">
<li>其它变量</li>
</ol>
<p><code>$?</code>: 保存前一个命令的返回码; <code>0</code>为运行成功，常用来判断上一个程序的退出状态。</p>
<p><code>$$</code>: 当前shell的进程号</p>
<p><code>$!</code>: 上一个子进程的进程号</p>
<p><code>$#</code>: 传给脚本或函数的参数个数, 即位置变量数减<code>1</code>(1代表脚本自身)<br />
<code>$*</code>和<code>$@</code>: 传给脚本的所有参数(不包含脚本本身), 每个参数以<code>$IFS</code>分隔（一般内为空格, TAB, 换行）; 两者的不同点是引号括起来时，<code>$*</code>会被作为一个整体，<code>$@</code>还是单个的参数。</p>
<pre><code>ct@ysx:~$ cat current_dir_testParam.sh
#!/bin/bash

echo &quot;current_dir${IFS}great&quot;

echo &#39;$*&#39;
echo -ne &quot;\t&quot;;
echo $*

echo &#39;$@&#39;
echo -ne &quot;\t&quot;;
echo $@

echo &#39;Each element in $*:&#39;

for i in &quot;$*&quot;; do
    echo -ne &quot;\t&quot;;
    echo $i;
done


echo &#39;Each element in $@:&#39;
for i in &quot;$@&quot;; do
    echo -ne &quot;\t&quot;;
    echo $i;
done

ct@ysx:~$ bash current_dir_testParam.sh sheng xin bao dian
current_dir     
great
$*
    sheng xin bao dian
$@
    sheng xin bao dian
Each element in $*:
    sheng xin bao dian
Each element in $@:
    sheng
    xin
    bao
    dian</code></pre>
</div>
<div id="bash_operator" class="section level2 hasAnchor" number="4.3">
<h2><span class="header-section-number">4.3</span> Bash操作符<a href="bash_string.html#bash_operator" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ol style="list-style-type: decimal">
<li>字符串操作符（替换操作符）</li>
</ol>
<p><code>${var:-word}</code>: 如果var存在且不为空, 返回它的值, 否则返回word<br />
<code>${var:=word}</code>: 如果var存在且不为空, 返回它的值, 否则将word赋给var, 返回它的值<br />
<code>${var:+word}</code>: 如果var存在且不为空, 返回word, 否则返回空<br />
<code>${var:?message}</code> 如果var存在且不为空, 返回它的值,<br />
否则显示“-bash: var: message”, 然后退出当前命令或脚本<br />
<code>${var:offset[:length]}</code> 从offset位置开始返回var的一个长为length的子串,<br />
若没有length, 则默认到var串末尾</p>
<div class="sourceCode" id="cb156"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb156-1"><a href="bash_string.html#cb156-1" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">${var</span><span class="op">:?</span>message<span class="va">}</span></span>
<span id="cb156-2"><a href="bash_string.html#cb156-2" tabindex="-1"></a><span class="ex">-bash:</span> var: message</span>
<span id="cb156-3"><a href="bash_string.html#cb156-3" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> var=<span class="st">&#39;sheng xin bao dian&#39;</span></span>
<span id="cb156-4"><a href="bash_string.html#cb156-4" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">${var</span><span class="op">:</span><span class="dv">6</span><span class="op">:</span><span class="dv">3</span><span class="va">}</span></span>
<span id="cb156-5"><a href="bash_string.html#cb156-5" tabindex="-1"></a><span class="ex">xin</span></span>
<span id="cb156-6"><a href="bash_string.html#cb156-6" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">${var</span><span class="op">:?</span>message<span class="va">}</span></span>
<span id="cb156-7"><a href="bash_string.html#cb156-7" tabindex="-1"></a><span class="ex">sheng</span> xin bao dian</span>
<span id="cb156-8"><a href="bash_string.html#cb156-8" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">$?</span></span>
<span id="cb156-9"><a href="bash_string.html#cb156-9" tabindex="-1"></a><span class="ex">0</span></span>
<span id="cb156-10"><a href="bash_string.html#cb156-10" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> unset var</span>
<span id="cb156-11"><a href="bash_string.html#cb156-11" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">${var</span><span class="op">:?</span>message<span class="va">}</span></span>
<span id="cb156-12"><a href="bash_string.html#cb156-12" tabindex="-1"></a><span class="ex">-bash:</span> var: message</span>
<span id="cb156-13"><a href="bash_string.html#cb156-13" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">$?</span></span>
<span id="cb156-14"><a href="bash_string.html#cb156-14" tabindex="-1"></a><span class="ex">1</span></span>
<span id="cb156-15"><a href="bash_string.html#cb156-15" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">${var</span><span class="op">:=</span>current_dir<span class="va">}</span></span>
<span id="cb156-16"><a href="bash_string.html#cb156-16" tabindex="-1"></a><span class="ex">current_dir</span></span>
<span id="cb156-17"><a href="bash_string.html#cb156-17" tabindex="-1"></a><span class="ex">ct@ysx:~$</span> echo <span class="va">${var}</span></span>
<span id="cb156-18"><a href="bash_string.html#cb156-18" tabindex="-1"></a><span class="ex">current_dir</span></span></code></pre></div>
<ol start="2" style="list-style-type: decimal">
<li>模式匹配操作符</li>
</ol>
<p><code>${var#pattern}</code> 从var头部开始, 删除和pattern匹配的最短模式串, 然后返回 剩余串</p>
<p><code>${var##pattern}</code> 从var头部开始, 删除和pattern匹配的最长模式串, 然后返回 剩余串, <code>basename path＝${path##*/}</code></p>
<p><code>${var%pattern}</code> 从var尾部开始, 删除和pattern匹配的最短模式串, 然后返回 剩余串, <code>dirname path＝${path%/*}</code></p>
<p><code>${var%%pattern}</code> 从var尾部开始, 删除和pattern匹配的最长模式串, 然后返回 剩余串</p>
<p><code>${var/pattern/string}</code> 用string替换var中和pattern匹配的最长模式串</p>
<p>个人最常用的是最后一个，常用于<code>for</code>循环中。</p>
<pre><code>ct@ysx:~$ var=&#39;sheng xin bao dian good&#39;
ct@ysx:~$ ${var/good/great}
-bash: sheng: command not found
ct@ysx:~$ echo ${var/good/great}
sheng xin bao dian great</code></pre>
<p>比如获取fastq文件的名字部分</p>
<pre><code>for i in `ls *_1.fq.gz`; do j=${i/_1.fq.gz/}; echo &quot;$j&quot;; done</code></pre>
</div>
<div id="bash_logic" class="section level2 hasAnchor" number="4.4">
<h2><span class="header-section-number">4.4</span> Shell中条件和test命令<a href="bash_string.html#bash_logic" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>Bash可以使用<code>[ … ]</code>结构或<code>test</code>命令测试复杂条件<br />
格式: <code>[ expression ]</code> 或 <code>test expression</code><br />
返回一个代码, 表明条件为真还是为假, 返回<code>0</code>为真, 否则为假。<br />
注: 左括号<code>后</code>和右括号<code>前空格</code>是<strong>必须的</strong>语法要求</p>
<ol style="list-style-type: decimal">
<li>文件测试操作符</li>
</ol>
<p><code>-d file</code>: file存在并且是一个目录<br />
<code>-e file</code>: file存在<br />
<code>-f file</code>: file存在并且是一个普通文件<br />
<code>-g file</code>: file存在并且是SGID(设置组ID)文件<br />
<code>-r file</code>: 对file有读权限<br />
<code>-s file</code>: file存在并且不为空<br />
<code>-u file</code>: file存在并且是SUID(设置用户ID)文件<br />
<code>-w file</code>: 对file有写权限<br />
<code>-x file</code>: 对file有执行权限, 如果是目录则有查找权限<br />
<code>-O file</code>: 拥有file<br />
<code>-G file</code>: 测试是否是file所属组的一个成员<br />
<code>-L file</code>: file为符号链接<br />
<code>file1 –nt file2</code>: file1比file2新</p>
<p><code>file1 –ot file2</code>: file1比file2旧</p>
<p>举两个例子</p>
<pre><code>ct@ysx:~$ touch older
ct@ysx:~$ touch newer

ct@ysx:~$ if test -e older; then echo &quot;older esists&quot;; fi
older esists
ct@ysx:~$ if test -s older; then echo &quot;older is unempty&quot;; fi
ct@ysx:~$ if [ -s older ]; then echo &quot;older is unempty&quot;; fi
ct@ysx:~$ if [ ! -s older ]; then echo &quot;older is empty&quot;; fi
older is empty
ct@ysx:~$ if [ newer -nt older ]; then echo &quot;newer&quot;; fi
newer</code></pre>
<ol start="2" style="list-style-type: decimal">
<li>字符串操作符</li>
</ol>
<p><code>str1=str2</code> str1和str2匹配<br />
<code>str1!=str2</code> str1和str2不匹配<br />
<code>str1&gt;str2</code> str1大于str2<br />
<code>-n str</code> str的长度大于0（不为空）
<code>-z str</code> str的长度为0（空串），常用于判断必须的命令行参数是否传入</p>
<pre><code># 字符串的大小比较的是最先遇到的不同的ASCII码的大小
ct@ysx:~$ if test &quot;10&quot;&gt;&quot;20&quot;; then echo &quot;10&gt;20&quot;; fi
10&gt;20
ct@ysx:~$ if test 10&gt;20; then echo &quot;10 &lt; 20&quot;; fi</code></pre>
<ol start="3" style="list-style-type: decimal">
<li><strong>整数</strong>操作符</li>
</ol>
<p>var1 –eq var2 var1等于var2<br />
var1 –ne var2 var1不等于var2<br />
var1 –ge var2 var1大于等于var2<br />
var1 –gt var2 var1大于var2<br />
var1 –le var2 var1小于等于var2<br />
var1 –lt var2 var1小于var2</p>
<p><code>ge</code>: great equal; <code>gt</code>: great than</p>
<p><strong>需要注意的是常用的数学运算符给了字符串比较，数字比较使用的却是英文缩写</strong></p>
<p>数学表达式也可以</p>
<pre><code>if (( 3&gt;2 )); then echo &#39;TRUE&#39;; fi
TRUE</code></pre>
<ol start="4" style="list-style-type: decimal">
<li>逻辑操作符</li>
</ol>
<p><code>!expr</code> 对expr求反
<code>expr1 &amp;&amp; expr2</code> 对expr1与expr2求逻辑与, 当expr1为假时不再执行expr2<br />
<code>expr1 || expr2</code> 对expr1与expr2求逻辑或, 当expr1为真时不再执行expr2</p>
</div>
<div id="bash_flow" class="section level2 hasAnchor" number="4.5">
<h2><span class="header-section-number">4.5</span> Shell流控制<a href="bash_string.html#bash_flow" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ol style="list-style-type: decimal">
<li>条件语句: if</li>
</ol>
<p><code>if</code>, <code>then</code>, <code>elif</code>, <code>else</code>, <code>fi</code>是关键词，其它的是需要替换掉的。</p>
<pre><code>if conditions; then
    do sth when conditions are true
elif another_conditions; then
    do sth when another_conditions are true
else:
    do sth when above condiitons are all false
fi</code></pre>
<pre><code>if test $guanzhu_sxbd == &quot;already&quot;; then
    echo &quot;Enjoy it&quot;
elif test $guanzhu_hjyz == &quot;already&quot;; then
    echo &quot;Enjoy it&quot;
else
    echo &quot;Guan zhu them&quot;
fi

Enjoy it</code></pre>
<ol start="2" style="list-style-type: decimal">
<li>确定性循环: <code>for do done</code> <strong>常用的批量操作方式</strong></li>
</ol>
<p>遍历一个列表，取出每个元素，针对性操作。</p>
<pre><code>for i in `ls *_1.fq.gz`; do 
    echo &quot;$i&quot;; 
done</code></pre>
<ol start="3" style="list-style-type: decimal">
<li>不确定性循环: <code>while</code>和<code>until</code></li>
</ol>
<pre><code>declare -i a #定义整数变量
a=1   # 初始化变量
while test $a -lt 3; do
    echo $a
    a=$a+1
done 

echo $a</code></pre>
<ol start="4" style="list-style-type: decimal">
<li>选择结构: <code>case</code>和<code>select</code> (类似getopts)</li>
</ol>
<pre><code>ct@ysx:~$ cat select_case.sh

PS3=&quot;Input the position of selected parameter (1 for exit):&quot;

select opts in a b c d
do
    case $opts in
        a)
            exit 0;
            ;;
        b)
            echo &quot; Parameters $opts&quot;
            ;;
        c)
            echo &quot; Parameters $opts&quot;
            ;;
        d)
            echo &quot; Parameters $opts&quot;
            ;;
        ?)
            echo &quot;Unknown&quot;
            ;;
    esac
done

ct@ysx:~$ bash select_case.sh 
1) a
2) b
3) c
4) d
Input the position of selected parameter (1 for exit):2
 Parameters b
Input the position of selected parameter (1 for exit):3
 Parameters c
Input the position of selected parameter (1 for exit):4
 Parameters d
Input the position of selected parameter (1 for exit):1
</code></pre>
<ol start="5" style="list-style-type: decimal">
<li>命令<code>shift</code></li>
</ol>
<p>将存放在位置变量中的命令行参数依次向左传递<code>shift n</code> 命令行参数向左传递<code>n</code>个参数串</p>
<pre><code>ct@ysx:~$ cat current_dir_testParam.sh
#!/bin/bash

echo &#39;Each element in $*:&#39;

for i in &quot;$*&quot;; do
    echo -ne &quot;\t&quot;;
    echo $i;
done

echo $1
shift

for i in &quot;$*&quot;; do
    echo -ne &quot;\t&quot;;
    echo $i;
done
ct@ysx:~$ bash current_dir_testParam.sh sheng xin bao dian
Each element in $*:
    sheng xin bao dian
sheng
    xin bao dian</code></pre>
</div>
<div id="bash_function" class="section level2 hasAnchor" number="4.6">
<h2><span class="header-section-number">4.6</span> Shell函数<a href="bash_string.html#bash_function" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p><code>function function_name () { function body}</code>定义函数，函数参数的获取同命令行参数获取。</p>
<pre><code>ct@ysx:~$ cat test_func.sh 
function show_current_dir () {
    echo $@
    echo $1
}

show_current_dir &quot;current_dir great&quot; &quot;SXBD great&quot;
ct@ysx:~$ bash test_func.sh
current_dir great SXBD great
current_dir great</code></pre>
</div>
<div id="bash_inputoutput" class="section level2 hasAnchor" number="4.7">
<h2><span class="header-section-number">4.7</span> 输入输出<a href="bash_string.html#bash_inputoutput" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ol style="list-style-type: decimal">
<li>I/O重定向</li>
</ol>
<p><a href="http://mp.weixin.qq.com/s/zL9Mw_2ig48gHrIjKM0CMw">管道、标准输入输出</a>之前有过详细介绍。</p>
<p><code>&lt;</code>: 输入重定向</p>
<p><code>&gt;</code>: 输出重定向(没有文件则创建, 有则覆盖)</p>
<p><code>&gt;&gt;</code>: 输出重定向(没有则创建, 有则追加到文件尾部)</p>
<p><code>&lt;&lt;</code>: 输入重定向(here文档)</p>
<pre><code>command &lt;&lt; label  
input…  
label  
说明:  使一个命令的输入为一段shell脚本(input…), 直到标号(label)结束  </code></pre>
<pre><code>ftp: USER=anonymous  
PASS=YC@163.com  
#-i: 非交互模式 -n: 关闭自动登录  
ftp –i –n &lt;&lt; END 
open ftp.163.com  
user $USER $PASS  
cd /pub  
close  
END
#END标记输入结束 </code></pre>
<ol start="2" style="list-style-type: decimal">
<li>字符串I/O操作</li>
</ol>
<p>字符串输出: <code>echo</code></p>
<p>命令选项: <code>-e</code>: 启动转义序列 <code>-n</code>: 取消输出后换行 (前面已经用到过)</p>
<ol start="3" style="list-style-type: decimal">
<li>字符串输入: <code>read</code> 可以用于用户交互输入, 也可以用来一次处理文本文件中的一行</li>
</ol>
<p>命令选项:</p>
<pre><code>ct@ysx:~$ read -p &quot;Enter the best tutorial: &quot; tutorial
Enter the best tutorial: Sheng Xin Bao Dian
ct@ysx:~$ echo $tutorial
Sheng Xin Bao Dian

# 隐藏输入内容
ct@ysx:~$ read -s -p &quot;Enter your password: &quot; password
Enter your password: 
ct@ysx:~$ echo $password
haha</code></pre>
</div>
<div id="command_parameter" class="section level2 hasAnchor" number="4.8">
<h2><span class="header-section-number">4.8</span> 命令行处理 命令行处理命令<a href="bash_string.html#command_parameter" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p><code>getopts</code> 有两个参数, 第一个为字母和冒号组成的选项列表字符串, 第二个为一个变量名</p>
<p>选项列表字符串以冒号开头的选项字母排列组成, 如果一选项需要一个参数则该选项字母后跟一个冒号</p>
<p><code>getopts</code>分解第一参数, 依次将选项摘取出来赋给第二个参数变量</p>
<p>如果某选项有参数, 则读取参数到内置变量<code>OPTARG</code>中 内置变量<code>OPTIND</code>保存着将被处理的命令行参数（位置参数）的数值选项列表处理完毕<code>getopts</code>返回<code>1</code>, 否则返回<code>0</code> 如:</p>
<p>在我们推出的<a href="https://mp.weixin.qq.com/s/bsvB1k17Izom2ldgdwXrdg">一步绘图脚本</a>里面，就是使用<code>Bash</code>封装的R脚本，通过修改命令行参数，完成热图、柱状图、线图、Venn图、火山图、泡泡图等图形的绘制和定制。</p>
<pre><code>while getopts &quot;hf:m:a:A:b:I:t:x:l:j:J:d:F:G:H:P:L:y:V:D:c:C:B:X:Y:R:w:u:r:o:O:s:S:p:z:Z:v:e:E:i:&quot; OPTION
do
        case $OPTION in
                h)
                        usage
                        exit 1
                        ;;
                f)
                        file=$OPTARG
                        ;;
                m)
                        melted=$OPTARG
                        ;;
                .
                .
                .
                ?)
                        usage
                        exit 1
                        ;;
        esac
done                </code></pre>
</div>
<div id="process_monitor" class="section level2 hasAnchor" number="4.9">
<h2><span class="header-section-number">4.9</span> 进程和作业控制<a href="bash_string.html#process_monitor" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p><a href="https://mp.weixin.qq.com/s/TNU7X2mhfVVffaJ7NRBuNA">命令行运行监测和软件安装</a>文中讲述了部分监测命令。</p>
<p>如果一个命令需要运行比较久，一般使用<code>nohup cmmand &amp;</code>来放入后台不中断运行，这样推出终端也不影响程序。</p>
<p><code>command &amp;</code>是把程序放入后台。</p>
<p><code>jobs</code>: 查看后台进程</p>
<p><code>bg</code>: 显示后台进程, 即用Ctrl+z挂起或‘命令 &amp;’执行的进程</p>
<p><code>fg job_id</code>: 将后台进程转到前台执行</p>
<p><code>kill –9 process_id</code>: 强制杀掉某个进程</p>

</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="LinuxGreatTools.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="bioinfo-tools.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
  "sharing": {
    "github": false,
    "facebook": false,
    "twitter": false,
    "linkedin": false,
    "weibo": false,
    "instapaper": false,
    "vk": false,
    "whatsapp": false,
    "all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
  },
  "fontsettings": {
    "theme": "white",
    "family": "sans",
    "size": 2
  },
  "edit": {
    "link": null,
    "text": null
  },
  "history": {
    "link": null,
    "text": null
  },
  "view": {
    "link": null,
    "text": null
  },
  "download": ["Bash.pdf"],
  "search": {
    "engine": "fuse",
    "options": null
  },
  "toc": {
    "collapse": "subsection"
  }
});
});
</script>

</body>

</html>
